<template>
  <div class="container edition-heart">
    <div class="left">
      <img src="../../../public/images/indexLogo.6f8ac4f0.png" alt="" />
    </div>
    <div class="center">
      <ul>
        <li
          :class="{ 'nav-active': activeRoute.includes('/home') }"
          @click="router.push('/')"
        >
          首页
        </li>
        <li
          :class="{ 'nav-active': activeRoute.includes('/goods') }"
          @click="router.push('/goods')"
        >
          全部商品
        </li>
        <li
          :class="{ 'nav-active': activeRoute.includes('/user') }"
          @click="router.push('/user/center')"
        >
          个人中心
        </li>
        <li
          :class="{ 'nav-active': activeRoute.includes('/order') }"
          @click="router.push('/order')"
        >
          我的订单
        </li>
        <li
          :class="{ 'nav-active': activeRoute.includes('/free') }"
          @click="router.push('/free')"
        >
          专属福利
        </li>
      </ul>
    </div>
    <div class="right">
      <input
        type="text"
        placeholder="搜索全部商品直接回车"
        v-model="key"
        @keyup.enter="searchKeyFn"
      />
      <div @click="searchKeyFn">
        <img src="../../../public/images/search.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router'
import { ref, watch, inject } from 'vue'

const { searchFn } = inject('data') as {
  searchFn: any
}

const key = ref<string | null>(null)

const route = useRoute()
const router = useRouter()

const activeRoute = ref('/')
watch(
  () => route.fullPath,
  () => {
    activeRoute.value = route.fullPath
  },
)

const searchKeyFn = () => {
  router.push('/goods')
  searchFn.value = key.value
  key.value = null
}
</script>

<style lang="less" scoped>
.nav-active {
  color: #0a328e;
  font-weight: 700;
}

.container {
  height: 118px;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .center {
    font-size: 16px;
    font-weight: 500;
    ul {
      display: flex;
      align-items: center;
      width: 560px;
      justify-content: space-around;
      li {
        text-align: center;
        cursor: pointer;
      }
    }
  }

  .right {
    display: flex;
    align-items: center;
    input {
      width: 214px;
      height: 40px;
      border: 1px solid #dedede;
      border-radius: 20px 0px 0px 20px;
      outline: none;
      text-indent: 1em;
    }
    div {
      width: 50px;
      height: 40px;
      background: #0a328e;
      border-radius: 0px 20px 20px 0px;
      display: flex;
      align-items: center;
      justify-content: center;
      img {
        display: inline-block;
        width: 20px;
        height: 18px;
      }
    }
  }
}
</style>
